﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://wpfimageviewer.codeplex.com
using System;
using System.ComponentModel;
using System.Drawing;
using BrainTechLLC;
using System.Threading;

namespace ImageAppDataModels
{
    public static class RecentlyUsedFileImages
    {
        public static RecentlyUsedList<FileImage, string> RecentlyUsedBitmaps = new RecentlyUsedList<FileImage, string>((fi) => fi.FileName);
        public static RecentlyUsedList<FileImage, string> RecentlyUsedTransformedBitmaps = new RecentlyUsedList<FileImage, string>((fi) => fi.FileName);
        public static RecentlyUsedList<FileImage, string> RecentlyUsedImageSources = new RecentlyUsedList<FileImage, string>((fi) => fi.FileName);
        public static RecentlyUsedList<FileImage, string> RecentlyUsedFileBytes = new RecentlyUsedList<FileImage, string>((fi) => fi.FileName);

        static RecentlyUsedFileImages()
        {
            RecentlyUsedBitmaps.ItemPushedFromList += new EventHandler<ObjectEventArgs<FileImage>>(RecentlyUsedBitmaps_ItemPushedFromList);
            RecentlyUsedImageSources.ItemPushedFromList += new EventHandler<ObjectEventArgs<FileImage>>(RecentlyUsedImageSources_ItemPushedFromList);
            RecentlyUsedFileBytes.ItemPushedFromList += new EventHandler<ObjectEventArgs<FileImage>>(RecentlyUsedFileBytes_ItemPushedFromList);
            RecentlyUsedTransformedBitmaps.ItemPushedFromList += new EventHandler<ObjectEventArgs<FileImage>>(RecentlyUsedTransformedBitmaps_ItemPushedFromList);
        }

        static void RecentlyUsedTransformedBitmaps_ItemPushedFromList(object sender, ObjectEventArgs<FileImage> e)
        {
            e.obj.TransformedBitmap = null;
        }

        static void RecentlyUsedFileBytes_ItemPushedFromList(object sender, ObjectEventArgs<FileImage> e)
        {
            e.obj.ImageBytesCached = null;            
        }

        static void RecentlyUsedImageSources_ItemPushedFromList(object sender, ObjectEventArgs<FileImage> e)
        {
            e.obj._imageSource = null;            
            e.obj.RaisePropertyChangedUIThread("ImageSource");            
        }

        private static void RecentlyUsedBitmaps_ItemPushedFromList(object sender, ObjectEventArgs<FileImage> e)
        {
            e.obj.BitmapCached = null;            
        }
    }
}
